package feizhu_0088;

/**
 * @author Jimmy Zhan WORKSTATION
 * @date 2023/6/20 22:45
 * 说明： 合并数组
 */

public class Mine {
    public void merge(int[] nums1, int m, int[] nums2, int n) {
        if (m == 0) {
            for (int i = 0; i < n; i++) {
                nums1[i] = nums2[i];
                return;
            }
        }
        if (n == 0){
            return;
        }

        int[] res = new int[m + n];
        int p1 = 0;
        int p2 = 0;
        for (int i = 0; i < m + n; i++) {
            if (p1 == m) {
                res[i] = nums2[p2];
                p2++;
                continue;
            }
            if (p2 == n) {
                res[i] = nums1[p1];
                p1++;
                continue;
            }
            if (nums1[p1] <= nums2[p2]) {
                res[i] = nums1[p1];
                p1++;
            } else {
                res[i] = nums2[p2];
                p2++;
            }
        }

        for (int i = 0; i < m + n; i++) {
            nums1[i] = res[i];
        }
    }
}
